package com.upu173.music.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.andbase.library.utils.AbDialogUtil;
import com.andbase.library.view.recycler.AbRecyclerViewAdapter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.upu173.music.R;
import com.upu173.music.activity.MusicMainActivity;
import com.upu173.music.model.Song;
import com.upu173.music.model.SongFolder;

import java.util.List;

public class SongFolderRecyclerViewAdapter extends AbRecyclerViewAdapter {

    private Context context;
    private List<SongFolder> songFolderList;
    private RequestManager glide;

    public SongFolderRecyclerViewAdapter(Context context, List<SongFolder> items) {
        super(context,items);
        this.context = context;
        this.songFolderList = items;
        glide = Glide.with(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateRecyclerViewHolder(ViewGroup parent, int viewType) {
        //必须这么写，不能用View.inflate
        View view = LayoutInflater.from(context).inflate(R.layout.music_item_song_folder_list,parent,false);
        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindRecyclerViewHolder(RecyclerView.ViewHolder holder, final int position) {
        RecyclerViewHolder recyclerViewHolder = (RecyclerViewHolder)holder;
        final SongFolder songFolder = songFolderList.get(position);
        recyclerViewHolder.nameTextView.setText(songFolder.getName());
        recyclerViewHolder.countTextView.setText(String.valueOf(songFolder.getCount()) + "首");
        recyclerViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               ((MusicMainActivity)context).onSongFolderClick(position);
            }
        });

        recyclerViewHolder.infoImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AbDialogUtil.showMessageDialog(context,songFolder.getName(),songFolder.getParentPath(),"确定",null);
            }
        });

        recyclerViewHolder.addImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((MusicMainActivity)context).addFolderClick(position);
            }
        });
    }


    public class RecyclerViewHolder extends RecyclerView.ViewHolder {

        public final ImageView imageView;
        public final TextView nameTextView;
        public final TextView countTextView;
        public final ImageView infoImageView,addImageView;
        public final View itemView;

        public RecyclerViewHolder(View view) {
            super(view);
            itemView = view;
            imageView = (ImageView) view.findViewById(R.id.item_image);
            nameTextView = (TextView) view.findViewById(R.id.item_name);
            countTextView = (TextView) view.findViewById(R.id.item_count);
            infoImageView = (ImageView) view.findViewById(R.id.item_info);
            addImageView = (ImageView) view.findViewById(R.id.item_add);

        }
    }


}